<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title></title>
    <script src="js/mui.min.js"></script>
    <script src="js/jquery-1.7.2.js"></script>
    <link href="css/mui.min.css" rel="stylesheet"/>
    <link href="css/index_class.css" rel="stylesheet"/>
    <script type="text/javascript" charset="UTF-8">
        mui.init();
    </script>
</head>

<body onload="getData(<?php echo $_GET["id"]; ?>
    <!--<?php //$add_price = 0;$cur_price = 100; ?>-->
<div class="mui-content">
    <div id="slider" class="mui-slider">
        <div class="mui-slider-group mui-slider-loop">
            <!-- 额外增加的一个节点(循环轮播：第一个节点是最后一张轮播) -->
            <div class="mui-slider-item mui-slider-item-duplicate">
                <a href="#">
                    <img id="img1" src="index.jpg">
                </a>
            </div>
            <!-- 第一张 -->
            <div class="mui-slider-item">
                <a href="#">
                    <img id="img2" src="index.jpg">
                </a>
            </div>
            <!-- 第二张 -->
            <div class="mui-slider-item">
                <a href="#">
                    <img id="img3" src="index.jpg">
                </a>
            </div>
            <!-- 第三张 -->
            <div class="mui-slider-item">
                <a href="#">
                    <img id="img4" src="index.jpg">
                </a>
            </div>
            <!-- 额外增加的一个节点(循环轮播：最后一个节点是第一张轮播) -->
            <div class="mui-slider-item mui-slider-item-duplicate">
                <a href="#">
                    <img id="img5" src="index.jpg">
                </a>
            </div>
        </div>
        <div class="mui-slider-indicator">
            <div class="mui-indicator mui-active"></div>
            <div class="mui-indicator"></div>
            <div class="mui-indicator"></div>
        </div>
        <div id="goodSended">热拍中</div>
    </div>
    <!--轮播图结束-->
    <ul class="mui-table-view msg-list">
        <li class="mui-table-view-cell mui-media">
            <span>竞拍倒计时</span>
            <span id="countdown"></span>
        </li>
        <li class="mui-table-view-cell mui-media">
            <span>当前价格</span>
            <span id="newPrice">

            	
            	</span>
        </li>
        <li class="mui-table-view-cell">
						<span class="mui-pull-left mui-font-listItem">
										商品名称
									</span>
                        <span id="rob_name" class="mui-pull-right mui-font-listContent">

									</span>
        </li>
        <li class="mui-table-view-cell">
						<span class="mui-pull-left mui-font-listItem">
										商品描述
									</span>
                        <span id="rob_des" class="mui-pull-right mui-font-listContent">

									</span>
        </li>
    </ul>
    <div class="mui-scroll">
        <ul class="mui-table-view mui-table-view-chevron peopleAround">
            <li class="mui-table-view-cell mui-media">
                最新竞拍榜TOP3
            </li>
            <li class="mui-table-view-cell">

                <a href="javascript:;">
                    <img name="headImg" class="mui-media-object mui-pull-left" src="index.jpg">

                    <div class="mui-media-body">
                        <span name="postName">李学弟</span>

                        <p name="postTime" class="mui-ellipsis">23:43</p>
                    </div>
                    <span id="mui-media-price"><span name="addPrice">
                    	
                    	<!--<?php $add_price = 80;echo $add_price; ?>-->
                    	</span></span>

                </a>
            </li>
            <li class="mui-table-view-cell">

                <a href="javascript:;">
                    <img name="headImg" class="mui-media-object mui-pull-left" src="index.jpg">

                    <div class="mui-media-body">
                        <span name="postName">李学弟</span>

                        <p name="postTime" class="mui-ellipsis">23:43</p>
                    </div>
                    <span id="mui-media-price"><span name="addPrice">
                    	
                        <!--<?php //$add_price = 80;echo $add_price; ?>-->
                    	</span></span>

                </a>
            </li>
            <li class="mui-table-view-cell">

                <a href="javascript:;">
                    <img name="headImg" class="mui-media-object mui-pull-left" src="index.jpg">

                    <div class="mui-media-body">
                        <span name="postName">李学弟</span>

                        <p name="postTime" class="mui-ellipsis">23:43</p>
                    </div>
                    <span id="mui-media-price"><span name="addPrice">
                    	
                    	<!--<?php $add_price = 80;echo $add_price; ?>-->
                    	</span></span>

                </a>
            </li>
            <li class="mui-table-view-cell mui-media">
                <a href="javascript:;">
                    已加载到底部
                </a>
            </li>
        </ul>
        <div id="mui-aaa">
        </div>
    </div>
</div>
<!--底部竞价功能区-->
<nav class="mui-bar mui-bar-tab">
    <div class="mui-forum-postBottomBox">
        <form action="" method="post">
            <input type="number" id="inputPrice" placeholder="我要加钱！！" name="add_price">
            <input type="button" id="addBTN" class="mui-forum-postBottomSend" value="加价">
        </form>

    </div>

</nav>
<script>

    var slider = mui("#slider");
    slider.slider({
        interval: 2000
    });


    function getCookie(name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg))
            return unescape(arr[2]);
        else
            return null;
    }
    function getData(id) {
        $.post("rob_db.php", {"module": "oldplat", "id": id},
            function (msg) {
                var x = msg.split("<script");//添加一个   >
                msg = x[0];alert(msg);
                msg = eval("("+msg+")");
                document.getElementById("img1").src =msg['img3'];
                document.getElementById("img2").src = msg['img1'];
                document.getElementById("img3").src = msg['img2'];
                document.getElementById("img4").src = msg['img3'];
                document.getElementById("img5").src = msg['img1'];
                $("#rob_name").html(msg["good_name"]);
                $("#rob_des").html(msg["good_info"]);
                $("#newPrice").html(<?php echo $_COOKIE["newPrice"]?>);
            }
        )
    }

    //判断商品状态

    //var goodStatus=0;
    //设置竞拍商品的状态goodStatus,0为待拍,1为待付款，2为待发货，3为待收货

    //设定倒计时定时器
    var interval = 1000;

    function ShowCountDown(year, month, day,hour,min,second,divname,nickname,f_id) {
        var now = new Date();
        var endDate = new Date(year, month - 1, day,hour,min,second);
        //两个时间相差的毫秒数
        var leftTime = endDate.getTime() - now.getTime();
        //毫秒数转化成秒数
        var leftsecond = parseInt(leftTime / 1000);
        //ar day1=parseInt(leftsecond/(24*60*60*6));
        var day1 = Math.floor(leftsecond / (60 * 60 * 24));
        var hour = Math.floor((leftsecond - day1 * 24 * 60 * 60) / 3600);
        var minute = Math.floor((leftsecond - day1 * 24 * 60 * 60 - hour * 3600) / 60);
        var second = Math.floor(leftsecond - day1 * 24 * 60 * 60 - hour * 3600 - minute * 60);
        var cc = document.getElementById(divname);
        if(day1<0){
            $.post("dealrobber_platdb.php",{"f_id":<?php echo $_REQUEST['id'];?>},function(){alert(1)});
            if(nickname+f_id==getCookie("f_nickname"+f_id)){//判断是否为该用户
                goodStatus=1;
                //将货物id传过去，获取当前最高价的f_nickname即wechat_name//$.post将数据传过去，把当前的id传过去，修改状态值
                window.location.href="http://1.dlxsifaner.applinzi.com/rob_win_book.php?id="+f_id;//付定金页面
            }
            else{
                alert("竞拍结束！");
                window.location.href="http://dlxsifaner.applinzi.com/robber_form.php";//跳转首页！
            }
        }else
        {
            cc.innerHTML = day1 + "天" + hour + "时" + minute + "分" + second+"秒";
        }
    }
    
    var d = new Date(new Date().getTime());
    window.setInterval(function () {
        ShowCountDown(d.getFullYear(), (d.getMonth()+1), (d.getDate()+1),d.getHours(),d.getMinutes(),d.getSeconds(),"countdown",getCookie("nickname"),<?php echo $_REQUEST['id'];?>);//后面参数的数值是传进去的！
    }, interval);
    //设置综合摁钮状态
    var addBTN = document.getElementById("addBTN");
    var inputPrice = document.getElementById("inputPrice");
        //商品的状态标签
    var goodSend = document.getElementById("goodSended");

    //igManager用于是否为管理员
    var isManager =getCookie('yes');
        //if (!isManager && goodStatus==3) {
        //addBTN.className = "mui-forum-postBottomSend";
        // addBTN.value = "收货";
         // addBTN.style.backgroundColor = "chartreuse";
        // addBTN.style.color = "white";
        //addBTN.addEventListener("tap", function () {
            //    //在此处处理   买家  确认收货流程 
        //   alert("收货成功");
        // });
        //  inputPrice.style.display = "none";
        //   addBTN.style.width = "100%";
        //  }
        //else if (!isManager && goodStatus==1) {
        // addBTN.className = "mui-forum-postBottomSend";
        // addBTN.value = "付款";
        // addBTN.style.backgroundColor = "red";
        // addBTN.style.color = "white";
        // addBTN.addEventListener("tap", function () {
            //在此处处理  买家  付款流程
        //window.location.href="pay/example/jsapi.php?name="+$('#rob_name').html()+"&fee="+$('#newPrice').html();
            //alert("付款成功");
        // });
        //非竞价阶段显示不同样式
        // inputPrice.style.display = "none";
        //  addBTN.style.width = "100%";
        // }
    //未发货时管理员可以执行删除
        if (isManager) {//else
           inputPrice.style.display = "none";
           addBTN.style.backgroundColor = "red";
           addBTN.value = "删除";
           addBTN.style.width = "100%";
          addBTN.type='button';
          addBTN.addEventListener("tap", function () {
          $.post("rob_db.php", {"module": "delect", 'id':<?php echo $_REQUEST['id'];?>},
          function () {
              alert("删除成功！！");
             window.location.href="robber_form.php";
                });
        });
    }
    //未发货时管理员可以执行删除
        // // else if (isManager) {
        // inputPrice.style.display = "none";
         // addBTN.style.backgroundColor = "green";
        /// addBTN.value = "发货";
        //addBTN.style.width = "100%";
        // addBTN.addEventListener("tap", function () {
            //在此处  行使  管理员的发货功能
        //alert("管理员触发了发货功能");
        // });
        // }
    // 商品图标签样式变化（是否售出标签）
                       // if (goodStatus) {
                       //  goodSend.innerHTML = "已中标";
                       //  goodSend.style.backgroundColor = "#ADFF2F";
                       // }
    //获取商品ID
                       // var goodID=<?php //echo $_GET['id'];?>;//$getIDid
    //利用ajax动态实现竞拍（05-16 ）

    $("#addBTN").bind("tap", function() {
        //获取出价时间
        var myDate =new Date();
        var hour=myDate.getHours();
        var minute=myDate.getMinutes()+1;
        var postTime = hour+":"+minute;
        //获取微信名、头像(这里调试时先用固定值)
        var username="ddd";<?php// echo $_COOKIE["nickname"]?>;
        var headImgUrl="index.jpg";<?php// echo $_COOKIE["headimgurl"]?>;
        //获取提高的价格（input框内）
        var inputPrice = document.getElementById("inputPrice").value;
        if(inputPrice==""){
            alert("请输入提升的价格");
            return;
        }
        //获取最新的价格
        $.ajax({
            url: "http://1.dlxsifaner.applinzi.com/jinpai.php",
            data: {
                checkcode:1,
                goodID:<?php echo $_GET["id"];?>,
                inputPrice: inputPrice,
                username:username,
                headImgUrl:headImgUrl,
                postTime:postTime
            },
            success: function(data) {
                autoRefresh();
            }
        });
    });
    //页面加载进来自动先刷新一遍
    autoRefresh();
    //获取各个需要显示更新的span标签
    var currentPrice = document.getElementById("newPrice");
    var headImg=document.getElementsByName("headImg");
    var postName=document.getElementsByName("postName");
    var postTime=document.getElementsByName("postTime");
    var addPrice=document.getElementsByName("addPrice");
    //每隔固定时长自动刷新的方法
    function autoRefresh(){
        $.ajax({
            url:"http://1.dlxsifaner.applinzi.com/jinpai.php",
            data:{
                checkcode:0,
                goodID:<?php echo $_GET["id"];?>
            },
                success:function(data){alert(data);
                //解析JSON格式的数据
                var jsonobj=JSON.parse(data);
                //alert(jsonobj.second.record_Price);
                //获取到返回的三个值之后就更新自己页面的TOP3榜单和最新价格（价格仅供参考）

                currentPrice.innerText=jsonobj.first.record_Price;
                //更新竞价榜单第一条
                headImg[0].src=jsonobj.first.record_Wechat_headImgUrl;
                postName[0].innerText=jsonobj.first.record_Wechat_name;
                postTime[0].innerText=jsonobj.first.record_postTime;
                addPrice[0].innerText=jsonobj.first.record_Price;
                //更新竞价榜单第二条
                headImg[1].src=jsonobj.second.record_Wechat_headImgUrl;
                postName[1].innerText=jsonobj.second.record_Wechat_name;
                postTime[1].innerText=jsonobj.second.record_postTime;
                addPrice[1].innerText=jsonobj.second.record_Price;
                //更新竞价榜单第三条
                headImg[2].src=jsonobj.third.record_Wechat_headImgUrl;
                postName[2].innerText=jsonobj.third.record_Wechat_name;
                postTime[2].innerText=jsonobj.third.record_postTime;
                addPrice[2].innerText=jsonobj.third.record_Price;
            }
        });
    }

    window.setInterval(function () {
        autoRefresh();

    },3000);

</script>
</body>

</html>